package com.yzt.message.observer;

import com.yzt.message.widget.chatinput.widget.ChatInputView;

import java.util.ArrayList;
import java.util.List;

/**
 * author : Irene
 * e-mail : 821970751@qq.com
 * date   : 2020/5/8 17:35
 * desc   :
 */
public class ChatInputLoadManager {

    public static List<ChatInputLoadObservable> logoutObservers = new ArrayList<>();

    public interface ChatInputLoadObservable {

        void sendInputView(ChatInputView inputView);

        void sendChat(String targetId, String nickName);
    }

    private ChatInputLoadManager() {

    }

    static class InstanceHolder {
        final static ChatInputLoadManager INSTANCE = new ChatInputLoadManager();
    }

    public static ChatInputLoadManager getInstance() {
        return ChatInputLoadManager.InstanceHolder.INSTANCE;
    }

    public void registerChatInputLoadObservable(ChatInputLoadManager.ChatInputLoadObservable observable) {
        if (null != observable) {
            if (!logoutObservers.contains(observable)) {
                logoutObservers.add(observable);
            }
        }
    }

    public void unRegisterChatInputLoadObservable(ChatInputLoadManager.ChatInputLoadObservable observable) {
        if (null != observable) {
            logoutObservers.remove(observable);
        }
    }

    public void sendInputView(ChatInputView inputView) {
        for (ChatInputLoadManager.ChatInputLoadObservable observable : logoutObservers) {
            observable.sendInputView(inputView);
        }
    }
}
